package cn.ad.param;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 创意查询参数
 * 
 * @author yujuan.zhang
 * @from 2016-06-14
 * @since V1.0
 *
 */
public class CreativeQuery extends AbstractPagingSortParam {

	/**
	 * 创意分组
	 */
	private Integer creativeGroupId;

	/**
	 * 搜索关键词， 创意名称或者ID
	 */
	private String search;

	/**
	 * 查询的开始日期
	 */
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date startDate;

	/**
	 * 查询的结束日期
	 */
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date endDate;

	/**
	 * 广告形式
	 */
	private Integer adFormat;

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Integer getAdFormat() {
		return adFormat;
	}

	public void setAdFormat(Integer adFormat) {
		this.adFormat = adFormat;
	}

	/**
	 * 默认按id排序
	 */
	@Override
	public String getSortby() {
		return StringUtils.isEmpty(super.getSortby()) ? "id" : super.getSortby();
	}

	/**
	 * 默认按降序排序
	 */
	@Override
	public ORDER getOrder() {
		return super.getOrder() == null ? ORDER.desc : super.getOrder();
	}

	public Map<String, Object> getSearchMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("key", this.search);
		map.put("startDate", this.startDate);
		map.put("endDate", this.endDate);
		map.put("adFormat", this.adFormat);
		map.put("sortby", this.getSortby());
		map.put("order", this.getOrder());
		return map;
	}


	public Integer getCreativeGroupId() {
		return creativeGroupId;
	}

	public void setCreativeGroupId(Integer creativeGroupId) {
		this.creativeGroupId = creativeGroupId;
	}
}
